const {contextBridge,ipcRenderer} = require('electron')

const sendUrl = async (url) => {
    return await ipcRenderer.invoke('on-url-event',url)
}

const alert = async (msg) => {
    return await ipcRenderer.invoke('on-alert-event',msg)
}

const open = (url) => {
    ipcRenderer.invoke('on-open-event',url)
}

const getFileList = async () => {
    const fileList = await ipcRenderer.invoke('on-getFiles-event')
    return fileList
}

const openDialog = () => {
    ipcRenderer.send('on-opendialog-event')
}

const onRenderEvent = () => {
    return new Promise((res,rej)=>{
        ipcRenderer.on('on-renderer-event',(e,msg)=>{
            res(msg)
        })
    })
}

contextBridge.exposeInMainWorld("myApi",{
    sendUrl,
    alert,
    open,
    getFileList,
    openDialog,
    onRenderEvent
})